<template>
	<div v-if="visible">
		<el-dialog :title="title" :visible.sync="visible" :before-close="closeDialog" custom-class="add_dialog"
			append-to-body>
			<el-upload class="upload-demo" accept=".xlsx,.xls" drag ref="upload" action="#" :show-file-list="false"
				:before-upload="before_Upload" :limit="1" :headers="headers">
				<svg-icon icon-class="shangchuan" class-name="el-icon-upload" />
				<div class="el-upload__text">{{ $t('text.uploadFilePrompt') }}</div>
			</el-upload>
			<span slot="footer" class="dialog-footer">
				<div style="display:flex;justify-content: left;flex-wrap: wrap;margin-bottom: 10px;">
					<el-button :loading="downloadLoading" @click="download" style="margin-top:5px" type="success">{{
						$t('text.templateDownload') }}</el-button>
					<el-button v-if="template_type === 1" @click="getModelDictionary" style="margin-top:10px" type="primary">{{
						$t('text.accessoriesInformationQuery') }}</el-button>
					<el-button v-if="template_type === 1 || template_type === 2" @click="getWarehouseInfo" style="margin-top:5px"
						type="primary">{{
							$t('text.warehouseInformationQuery') }}</el-button>
					<el-button v-if="template_type === 3" @click="getBrandDictionary" style="margin-top:5px" type="primary">{{
						$t('text.brandInfo') }}</el-button>
					<el-button v-if="template_type === 3" @click="getPartsCalssfyDictionary" style="margin-top:5px"
						type="primary">{{
							$t('text.partsClassfyInfo') }}</el-button>
					<el-button v-if="template_type === 3" @click="getUnitDictionary" style="margin-top:5px" type="primary">{{
						$t('text.unitInfo') }}</el-button>
				</div>
				<el-button @click="closeDialog">{{ $t('el.popconfirm.close') }}</el-button>
			</span>
		</el-dialog>
		<!-- 错误提示 -->
		<el-dialog :title="title + $t('text.errorPrompt')" :visible.sync="visibleError" custom-class="add_dialog_error"
			append-to-body>
			<div>
				<i class="el-icon-error" style="color:#E47470;font-size:16px;margin-right:10px"></i>
				<span>{{ errInfo }}</span>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button @click="visibleError = false">{{ $t('el.popconfirm.close') }}</el-button>
			</span>
		</el-dialog>
	</div>
</template>
<script>
import { getSystemUploadTemplate } from '@/api/public'
export default {
	// template_type 1: 配件入库明细模板 2: 库位模板 3: 配件模板
	props: ['title', 'list', 'template_type'],
	components: {},
	data() {
		return {
			loading: false,
			visible: false,
			visibleError: false,
			headers: {
				'Content-Type': 'multipart/form-data'
			},
			info: {
				projectId: '', //渠道项目
				projectName: '', //渠道项目名称
			},
			rules: {
				projectId: [
					{
						required: true,
						message: this.$t('placeholderTip.pSelect'),
						trigger: 'change'
					}
				],
			},
			downloadLoading: false,
			errInfo: '' //错误信息提示
		}
	},
	mounted() { },
	beforeDestroy() { },
	methods: {
		getOpen() {
			this.visible = true
		},
		closeDialog() {
			this.visible = false
		},
		before_Upload(file) {
			if (this.template_type === 1 || this.template_type === 2 || this.template_type === 3) {
				let FormDatas = new FormData()
				FormDatas.append('file', file)
				this.$parent.getToLeadData(FormDatas)
			}
		},
		download() {
			// 下载
			this.downloadLoading = true
			getSystemUploadTemplate(Number(this.template_type)).then(res => {
				if (res.code === 200) {
					this.downloadLoading = false
					window.location.href = res.data
				}
			})
		},

		// 直接入库
		getModelDictionary() {
			this.$parent.getDataInfoVisible()
		},
		//库位、仓库
		getWarehouseInfo() {
			this.$parent.getWarehouseInfoVisible()
		},
		// 品牌
		getBrandDictionary() {
			this.$parent.getBrandInfoVisible()
		},
		// 配件分类
		getPartsCalssfyDictionary() {
			this.$parent.getPartsCalssfyInfoVisible()
		},
		// 单位信息查询
		getUnitDictionary() {
			this.$parent.getUnitInfoVisible()
		},
		getVisibleError(flag, err) {
			this.visibleError = flag
			this.errInfo = err
		}
	}
}
</script>

<style lang="scss" scoped>
::v-deep .add_dialog_error {
	width: 615px;
	height: auto !important;
	position: relative;

	.el-dialog__header {
		border-bottom: 1px solid #e4e4e4;
		text-align: left;
	}

	.el-dialog__body {
		height: auto;
	}

	.el-dialog__footer {
		border-top: 1px solid #e4e4e4;
		text-align: right;
	}

	.el-button:hover,
	.el-button:focus {
		color: #000;
	}

	.el-icon-upload:before {
		color: #dfb771;
	}

	.el-upload-dragger {
		width: 575px;
	}
}
</style>
<style lang="scss" scoped>
::v-deep .add_dialog {
	width: 615px;
	height: auto !important;
	position: relative;

	.el-dialog__header {
		border-bottom: 1px solid #e4e4e4;
		text-align: left;
	}

	.el-dialog__body {
		height: auto;
	}

	.el-dialog__footer {
		border-top: 1px solid #e4e4e4;
		text-align: right;
	}

	.el-button:hover,
	.el-button:focus {
		color: #000;
	}

	.el-icon-upload:before {
		color: #dfb771;
	}

	.el-upload-dragger {
		width: 575px;
	}
}
</style>
